package org.bopis.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.bopis.utilidades.Utilidades;

public class ResetPasswordForm extends ActionForm{

	private static final long serialVersionUID = 1L;
	
	private String pass1;
	private String pass2;	
	private String from;
	
	public String getPass1() {
		return pass1;
	}

	public void setPass1(String pass1) {
		this.pass1 = pass1;
	}

	public String getPass2() {
		return pass2;
	}

	public void setPass2(String pass2) {
		this.pass2 = pass2;
	}
	
	
	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	/**
	 * Validaciones del fomulario
  	 */
  	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 
  	{
    	ActionErrors errors = new ActionErrors();
		
    	//el screenname es obligatorio y debe de ser unico
    	if(Utilidades.isVacia(pass1) || Utilidades.isVacia(pass2)){
    		errors.add("error", new ActionMessage("forgot.pass.pass.null"));
    	}else{
    		if(!pass1.equals(pass2)){
    			errors.add("error", new ActionMessage("forgot.pass.not.equals"));
    		}    		
    	}
    	 	
    	    	
    	return errors;
  	}
	
  	/**
   	 * Resetea todas las propiedades a sus valores por defecto.
   	 */
  	public void reset(ActionMapping mapping, HttpServletRequest request) 
  	{
  		this.pass1 = null;
  		this.pass2 = null;
  		this.from = null;
  	}
	
}
